package com.data.modules.online.cgform.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.data.common.constant.CommonConstant;
import com.data.modules.online.cgform.entity.OnlCgformIndex;
import com.data.modules.online.cgform.mapper.OnlCgformHeadMapper;
import com.data.modules.online.cgform.mapper.OnlCgformIndexMapper;
import com.data.modules.online.cgform.service.IOnlCgformIndexService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;

@Slf4j
@Service
public class OnlCgformIndexServiceImpl extends ServiceImpl<OnlCgformIndexMapper, OnlCgformIndex> implements IOnlCgformIndexService {

    private static final Logger f214a = LoggerFactory.getLogger(OnlCgformIndexServiceImpl.class);
    @Autowired
    private OnlCgformHeadMapper onlCgformHeadMapper;

    private static /* synthetic */ java.lang.Object m178a(java.lang.invoke.SerializedLambda r4) {
        /*
        // Method dump skipped, instructions count: 188
        */
        throw new UnsupportedOperationException("Method not decompiled: com.data.modules.online.cgform.service.p013a.OnlCgformIndexServiceImpl.m178a(java.lang.invoke.SerializedLambda):java.lang.Object");
    }

@Override
public void createIndex(String code, String databaseType, String tbname) {
        LambdaQueryWrapper<OnlCgformIndex> var4 = new LambdaQueryWrapper();
        var4.eq(OnlCgformIndex::getCgformHeadId, code);
        List var5 = this.list(var4);
        if (var5 != null && var5.size() > 0) {
            Iterator var6 = var5.iterator();

            while(var6.hasNext()) {
                OnlCgformIndex var7 = (OnlCgformIndex)var6.next();
                if (!CommonConstant.DEL_FLAG_1.equals(var7.getDelFlag()) && "N".equals(var7.getIsDbSynch())) {
                    String var8 = "";
                    String var9 = var7.getIndexName();
                    String var10 = var7.getIndexField();
                    String var11 = "normal".equals(var7.getIndexType()) ? " index " : var7.getIndexType() + " index ";
                    byte var13 = -1;
                    switch(databaseType.hashCode()) {
                        case -1955532418:
                            if (databaseType.equals("ORACLE")) {
                                var13 = 1;
                            }
                            break;
                        case -1620389036:
                            if (databaseType.equals("POSTGRESQL")) {
                                var13 = 3;
                            }
                            break;
                        case 73844866:
                            if (databaseType.equals("MYSQL")) {
                                var13 = 0;
                            }
                            break;
                        case 912124529:
                            if (databaseType.equals("SQLSERVER")) {
                                var13 = 2;
                            }
                    }

                    switch(var13) {
                        case 0:
                            var8 = "create " + var11 + var9 + " on " + tbname + "(" + var10 + ")";
                            break;
                        case 1:
                            var8 = "create " + var11 + var9 + " on " + tbname + "(" + var10 + ")";
                            break;
                        case 2:
                            var8 = "create " + var11 + var9 + " on " + tbname + "(" + var10 + ")";
                            break;
                        case 3:
                            var8 = "create " + var11 + var9 + " on " + tbname + "(" + var10 + ")";
                            break;
                        default:
                            var8 = "create " + var11 + var9 + " on " + tbname + "(" + var10 + ")";
                    }

                    this.onlCgformHeadMapper.executeDDL(var8);
                    var7.setIsDbSynch("Y");
                    this.updateById(var7);
                }
            }
        }

    }

    @Override
    public boolean isExistIndex(String countSql) {
        if (countSql == null) {
            return true;
        }
        Integer valueOf = Integer.valueOf(this.baseMapper.queryIndexCount(countSql));
        if (valueOf == null || valueOf.intValue() <= 0) {
            return false;
        }
        return true;
    }

@Override
public java.util.List<OnlCgformIndex> getCgformIndexsByCgformId(java.lang.String cgformId) {
        return ((OnlCgformIndexMapper)this.baseMapper).selectList((Wrapper)(new LambdaQueryWrapper<OnlCgformIndex>()).in(OnlCgformIndex::getCgformHeadId, new Object[]{cgformId}));
    }
}
